#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 06-Nov-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;

using Thn;
#endregion

namespace Thn.Interface.Vcl
{
    /// <summary>
    /// 
    /// </summary>
    [ToolboxItem(true), DefaultProperty("Text"), DefaultEvent("Click"), ToolboxBitmap(typeof(ResourceBeacon), "Thn.Interface.Vcl.Resources.Icons.Label.bmp")]
#if DEBUG
    public
#else
    public
#endif
 class Label : ControlBase
    {
        #region Fields
        #endregion

        #region Properties

        #region Auto Size
        //private bool mAutoSize = true;
        ///// <summary>
        ///// Gets/Sets whether this control's size will be adjusted automatically
        ///// when the Text property is modified.
        ///// </summary>
        //[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Whether changing text shall change size")]
        //public bool AutoSize
        //{
        //    get { return mAutoSize; }
        //    set { mAutoSize = value; }
        //}
        #endregion

        #region Multiline
        private bool mMultiline = true;
        /// <summary>
        /// Gets/Sets whether long text shall be rendered as multiple rows.
        /// </summary>
        [Browsable(true), DefaultValue(true), Category("Appearance"), Description("Whether long text shall be rendered as multiple rows")]
        public bool Multiline
        {
            get { return mMultiline; }
            set
            {
                mMultiline = value;
                Invalidate();
            }
        }
        #endregion

        #region Alignment
        private ContentAlignment mAlignment = ContentAlignment.MiddleLeft;
        /// <summary>
        /// Gets or Sets alignment of text
        /// </summary>
        [DefaultValue(ContentAlignment.MiddleLeft), Description("Gets or Sets alignment of text"), Category("Appearance")]
        public virtual ContentAlignment Alignment
        {
            get { return mAlignment; }
            set
            {
                if (mAlignment != value)
                {
                    mAlignment = value;
                    InvalidateLayout();
                }
            }
        }
        #endregion

        #region Text Style
        private TextStyle mTextStyle = TextStyle.Normal;
        /// <summary>
        /// Gets/Sets font style for rendering text.
        /// </summary>
        [Browsable(true), DefaultValue(TextStyle.Normal), Category("Appearance"), Description("Font style for rendering text")]
        public TextStyle TextStyle
        {
            get { return mTextStyle; }
            set
            {
                mTextStyle = value;
                Invalidate();
            }
        }
        #endregion

        #region Render Context
        private LabelRenderContext mRenderContext = null;
        /// <summary>
        /// Gets reference to current renderation context.
        /// </summary>
        protected LabelRenderContext RenderContext
        {
            get
            {
                if (mRenderContext == null) mRenderContext = CreateRenderContext();
                #region Defensive tracing
                else
                {
                    //already created
                }
                #endregion

                return mRenderContext;
            }
        }
        #endregion

        #endregion

        #region On Get Render Context
        /// <summary>
        /// Get reference to the renderation context which is used by <see cref="IControlRenderer"/>.
        /// </summary>
        protected override RenderContext OnGetRenderContext(Graphics canvas)
        {
            return RenderContext;
        }
        #endregion

        #region On Calculate Layout
        /// <summary>
        /// Perform layout calculations neccessary for this control.
        /// </summary>
        protected override void OnCalculateLayout()
        {
            Rectangle rCon = this.ClientRectangle;
            rCon = new Rectangle(rCon.Left, rCon.Top, rCon.Width - 1, rCon.Height - 1);//fix pixel offset bug

            //assign values to render context
            RenderContext.ControlRegion = rCon;
        }
        #endregion

        #region Create Render Context
        /// <summary>
        /// Create a new render context instance.
        /// </summary>
        protected virtual LabelRenderContext CreateRenderContext()
        {
            return new LabelRenderContext();
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Label()
        {
            //this.TabStop = false;
            SetStyle(ControlStyles.Selectable, false);
            this.Size = new Size(75, 22);
            //mTransparencyMethod = TransparencyMethod.ForcedPainting;
        }
        #endregion
    }
}
